package org.pro.core.validateCode;

import org.pro.core.properties.SecurityProperties;
import org.pro.core.validateCode.image.ImageValidateCodeGenerator;
import org.pro.core.validateCode.sms.DefaultSmsSender;
import org.pro.core.validateCode.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注入图片验证码
 * 当系统中不存在 Bean（ smsCodeSender）注入默认短信发送器
 * @author luoqiz
 *
 */
@Configuration
public class ValidateCodeBeanConfig {

	@Autowired
	private SecurityProperties securityProperties;
	
	@Bean
	@ConditionalOnMissingBean(name="imageValidateCodeGenerator")
	public ValidateCodeGenerator imageValidateCodeGenerator() {
		ImageValidateCodeGenerator imageValidateGenerator =new ImageValidateCodeGenerator();
		imageValidateGenerator.setSecurityProperties(securityProperties);
		return imageValidateGenerator;
	}
	
	@Bean
	@ConditionalOnMissingBean(name="smsCodeSender")
	public SmsCodeSender smsCodeSender() {
		return new DefaultSmsSender();
	}
}
